#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

const int maxn=1e3+10;

int main()
{
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++){
		string a;
		cin>>a;
		int l=0,r=a.length(),ans=0;
		while(l<r){
			if(a[l]=='1'&&a[r]=='1') break;
			if(a[l]=='1'&&a[r]!='1') r--;
			else if(a[l]!='1'&&a[r]=='1') l++;
			else l++,r--;
		}
		for(int j=l+1;j<r;j++){
			if(a[j]=='0') ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}
